import request from '@/utils/request'
import type {
  StatisticsOverview,
  MemberGrowthData,
  RevenueData,
  BookingData,
  CheckinData,
  PopularCourse,
  PopularCoach,
  StatisticsQueryParams
} from '@/types/api/statistics'
import type { BaseResponse } from '@/types/common/response'

/**
 * 数据统计管理相关API
 */
export const statisticsApi = {
  /**
   * 获取数据统计概览
   */
  getStatisticsOverview() {
    return request.get<StatisticsOverview>('/statistics/overview')
  },

  /**
   * 获取会员增长趋势数据
   * @param params 查询参数
   */
  getMemberGrowthData(params: StatisticsQueryParams) {
    return request.get<MemberGrowthData[]>('/statistics/members/growth', { params })
  },

  /**
   * 获取收入统计数据
   * @param params 查询参数
   */
  getRevenueData(params: StatisticsQueryParams) {
    return request.get<RevenueData[]>('/statistics/revenue/trends', { params })
  },

  /**
   * 获取课程预约统计数据
   * @param params 查询参数
   */
  getBookingData(params: StatisticsQueryParams) {
    return request.get<BookingData[]>('/statistics/booking', { params })
  },

  /**
   * 获取签到统计数据
   * @param params 查询参数
   */
  getCheckinData(params: StatisticsQueryParams) {
    return request.get<CheckinData[]>('/statistics/checkin', { params })
  },

  /**
   * 获取热门课程统计
   * @param params 查询参数
   */
  getPopularCourses(params: { limit?: number }) {
    return request.get<PopularCourse[]>('/statistics/popular-courses', { params })
  },

  /**
   * 获取热门教练统计
   * @param params 查询参数
   */
  getPopularCoaches(params: { limit?: number }) {
    return request.get<PopularCoach[]>('/statistics/popular-coaches', { params })
  },

  /**
   * 导出统计数据
   * @param params 查询参数
   */
  exportStatistics(params: StatisticsQueryParams & { type: string }) {
    return request.get<string>('/statistics/export', { params })
  }
}
